<?php

namespace App\Http\Controllers;

use App\User;
use Auth;
use Illuminate\Http\Request;

class EmailController extends Controller
{
  public function verify($token)
  {
    $user = User::where('confirmation_token', $token)->first();
    if (is_null($user)) {
      return redirect('/');
    }

    $user->is_active = 1;
    $user->confirmation_token = str_random(40);
    $user->save();
    Auth::login($user);
    \Flash::success('恭喜你激活成功，来添加一个问题吧~');
    return redirect('/question/create');
  }
}
